package atmGUI;

import util.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//菜单
public class MenuPanel extends JPanel implements ActionListener {
    private Icon queryImage = Util.getIcon("/image/buttonFind.jpg");//查询按钮图
    private Icon saveImage = Util.getIcon("/image/buttonGet.jpg");//取款按钮图
    private Icon withdrawalImage = Util.getIcon("/image/buttonSave.jpg");//存款按钮图
    private Icon changePwdImage = Util.getIcon("/image/buttonModify.jpg");//改密码按钮图
    private Icon quitImage = Util.getIcon("/image/buttonOff.jpg");//退出按钮图
    private JButton queryBtn;
    private JButton saveBtn;
    private JButton withdrawalBtn;
    private JButton changePwdBtn;
    private JButton quitBtn;
    private ATM_GUI_Main frame;//顶级容器实例

    public MenuPanel(ATM_GUI_Main frame) {
        this.frame = frame;
        //设置空布局
        this.setLayout(null);
        this.setOpaque(false);
        //查询按钮
        queryBtn = new JButton(queryImage);
        queryBtn.setBounds(850, 100, 140, 50);
        this.add(queryBtn);
        //取款按钮
        saveBtn = new JButton(saveImage);
        saveBtn.setBounds(850, 180, 140, 50);
        this.add(saveBtn);
        //存款按钮
        withdrawalBtn = new JButton(withdrawalImage);
        withdrawalBtn.setBounds(850, 260, 140, 50);
        this.add(withdrawalBtn);
        //改密码按钮
        changePwdBtn = new JButton(changePwdImage);
        changePwdBtn.setBounds(850, 340, 140, 50);
        this.add(changePwdBtn);
        //退出按钮
        quitBtn = new JButton(quitImage);
        quitBtn.setBounds(850, 420, 140, 50);
        this.add(quitBtn);
        queryBtn.addActionListener(this);//建立联系
    }

    @Override
    public void actionPerformed(ActionEvent e) {//当点击退出按钮时，切换到登陆界面
        if (e.getSource() == quitBtn) {
            frame.switchPanel("login");
        }
    }
}
